<%@ Page Language="C#"  MasterPageFile="~/templates/template.Master"AutoEventWireup="true" CodeBehind="editar.aspx.cs" Inherits="GesWork.maestros.editar" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


    <asp:content ID="df" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
      
        <asp:Repeater ID="Repeater1" runat="server"  DataSourceID="dsActividades">
        <ItemTemplate>
         <div class="recuadro">
      
                <!-- <b>ID:</b> -->
                <asp:Label ID="idLabel" runat="server"  Text='<%# Bind("ID") %>' Visible="false"></asp:Label>
                <br />
                
                <b>Propietario:</b>
                <asp:Label ID="OwnerLabel" runat="server" 
                    Text='<%# User.Identity.Name %>' /> 
                
                    
                <br /><br />
                         <div class="separador"></div>   
                        <br />
               
                
                <b>Tipo:</b>
                
                <asp:DropDownList ID="cmbACC_TypeTextBox" runat="server"   Text='<%# Bind("ACC_Type") %>' 
                    
                    DataTextField="description" DataValueField="id" 
                    onselectedindexchanged="TipoRelacionInsert" DataSourceID="dsTipo" 
                      >
                </asp:DropDownList>
                <asp:SqlDataSource ID="dsTipo" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [description], [id] FROM [ActivityType]">
                </asp:SqlDataSource>
                <br />
                <b>Estado:</b>
                <asp:DropDownList ID="cmbACC_StateTextBox" runat="server"    Text='<%# Bind("ACC_State") %>' 
                    
                    DataTextField="Description" DataValueField="ID" DataSourceID="dsEstado" 
                     >
                </asp:DropDownList>
                <asp:SqlDataSource ID="dsEstado" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Description], [ID] FROM [ActivityState]">
                </asp:SqlDataSource>
                <br />
                <b>Prioridad:</b>
                <asp:DropDownList ID="cmbACC_IDPriorityTextBox" runat="server"   Text='<%# Bind("ACC_IDPriority") %>'  
                   
                    DataTextField="Description" DataValueField="ID" DataSourceID="dsPrioridad" 
                     >
                </asp:DropDownList>
                
                <asp:SqlDataSource ID="dsPrioridad" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Description], [ID] FROM [ActivityPriority]">
                </asp:SqlDataSource>
                
                <br />
                <b>Categoria:</b>
                <asp:TextBox ID="ACC_CategoriesTextBox" runat="server"  Text='<%# Bind("ACC_Categories") %>' 
                    />
                    
                <br /><br />
                         <div class="separador"></div>   
                        <br />
               
             <asp:UpdatePanel runat="server" ID="updPanel">
             <ContentTemplate>
             
                <b>Tipo de relacion:

                    <asp:DropDownList ID="cmbOwnerByTypeIns" runat="server"  
                       AutoPostBack="True"  OnSelectedIndexChanged="TipoRelacionInsert" Text='<%# Bind("OwnerByType") %>'
                         >
                    <asp:ListItem Text="Oportunidad" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Empresa" Value="1"></asp:ListItem>
                    <asp:ListItem Text="Contacto" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                <br />
                
                <asp:Label ID="txtRelacionado" runat="server" Text="Relacionado con:" Visible="false"></asp:Label> 
                 <asp:DropDownList ID="CmbIDToUserIns" runat="server" 
                    DataSourceID="dsOportunityIns" DataTextField="Name" DataValueField="ID"  OnSelectedIndexChanged="cambioRelacion" 
                        AutoPostBack="True"  Visible="false" >
                    </asp:DropDownList>
                  <asp:label ID="lblIDToUser" runat="server" Text='<%# Bind("IDToUser") %>'
                   
                        Visible="false" ></asp:label>
                    
           
               
                <asp:SqlDataSource ID="dsContactIns" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Name]+' '+[FirstName]+' '+[LastName] as Name, [ID] FROM [Contact] ORDER BY FirstName"></asp:SqlDataSource>
                <asp:SqlDataSource ID="dsEnterpriseIns" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Name], [ID] FROM [Enterprise]"></asp:SqlDataSource>
                <asp:SqlDataSource ID="dsOportunityIns" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                    SelectCommand="SELECT [Name], [ID] FROM [Oportunity]"></asp:SqlDataSource>

                    
                   
               </ContentTemplate>
             </asp:UpdatePanel>
             
                 <br />
                         <div class="separador"></div>   
                        <br />
               
                    
                   
               
                
               
                
                <b>Asunto:</b>
                <asp:TextBox ID="SubjectTextBox" runat="server"  Text='<%# Bind("Subject") %>'></asp:TextBox>
                <br />
                <b>Detalle:</b>
                <asp:TextBox ID="MSG_TextTextBox" runat="server"  Text='<%# Bind("MSG_Text") %>' Height="200px" 
                            TextMode="MultiLine" Width="600px" 
                     />
                
                
                 <br /><br />
                         <div class="separador"></div>   
                        <br />
                        
                <b>Fecha de Inicio:</b>
                <asp:TextBox ID="StartDateTextBox" runat="server"  Text='<%# Bind("StartDate", "{0:dd/MM/yyyy}") %>'
                   />
                    <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
            
                <br />
                <b>Fecha de Fin:</b>
                <asp:TextBox ID="DueDateTextBox" runat="server"   Text='<%# Bind("DueDate", "{0:dd/MM/yyyy}") %>'/>
                <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="DueDateTextBox" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
                    </cc1:CalendarExtender>
               
                <br />
                 <b>Dura todo el dia:</b>
                <asp:CheckBox ID="AllDayEventCheckBox" runat="server"  Text='<%# Bind("AllDayEvent") %>'
                    />
              
              
               <br /><br />
                         <div class="separador"></div>   
                        <br />
                        
               
                <asp:UpdatePanel runat="server" ID="UpdatePanel1">
             <ContentTemplate>
           
                <b>Parentesco:</b>
                <asp:TextBox ID="ACC_IDParentActivityTextBox" runat="server"  Text='<%# Bind("ACC_IDParentActivity") %>' 
                    />
                
                <asp:ImageButton ID="lnkAddParent" runat="server"   
                 ImageUrl="~/images/btnAniadir.png"  CausesValidation="False"  style="position:relative; float:inherit;margin-left:420px;"
                    CommandName="New" />
                
                
                
                <br />
                                <asp:Panel runat="server" ID="pnlActividades" CssClass="modalPopup">

<script language="javascript">
function SetUniqueRadioButton(nameregex, rid)
    {
       re = new RegExp(nameregex);
       rb = document.getElementById(rid.id);
       var inputs = document.getElementsByTagName('input');
       for(i = 0; i < inputs.length; i++)
       {
          elm = inputs[i]
          if (elm.type == 'radio')
          {
             if (re.test(elm.name))
             {
                elm.checked = false;
             }
          }
       }
 
       rb.checked = true;
    }

</script>
                                
                                                   <table class="tblGeneral" >
                                                        <tr class="tblHeader">
                                                                <td>
                                                                
                                                                </td>
                                                                <td>
                                                                <b>Tipo</b>
                                                                </td>
                                                                <td>
                                                                <b>Tarea</b>
                                                                </td>
                                                                
                                                                <td>
                                                                <b>Fecha de Inicio</b>
                                                                </td>
                                                                
                                                                

                                                            </tr>
                                                            <asp:Repeater ID="rptPupPop" runat="server" DataSourceID="SqlDataSource1">
                                                            <ItemTemplate>
                                                            <tr>
                                                                <td>
                                                                <asp:RadioButton  runat="server" ID="activ" onclick=" SetUniqueRadioButton('Repeater1.*', this)" /> 
                                                                <asp:Label  runat="server" ID="lblID" Text='<%# Eval("ID") %>' Visible="false" />
                                                                </td>
                                                                <td>
                                                                <img src="../images/activitytype<%# Eval("ACC_Type")%>.png"  alt="Actividad" name="Actividad"/>
                                                                </td>
                                                                <td>
                                                                  <%# Eval("Subject")%> 
                                                                </td>
                                                                
                                                                <td>
                                                                <%# Eval("StartDate", "{0:dd/MM/yyyy}")%>
                                                                </td>
                                                               
                                                               

                                                            </tr>
                                                            </ItemTemplate>
                                                            </asp:Repeater>
                                                        </table>
                                                
                                                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                                    ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
                                                    
                                                            SelectCommand="SELECT Activity.ID, Activity.Subject, Activity.StartDate, Activity.ACC_IDPriority ,ActivityPriority.Description AS priority, Activity.ACC_Type
                                            FROM Activity, ActivityPriority WHERE ACC_IDPriority=ActivityPriority.ID  ORDER BY StartDate ">
                                                </asp:SqlDataSource>
                        <br/>
                                    <asp:ImageButton ID="btnSelectActivity" runat="server"  OnClick="btnSelectActivity_Click" ImageUrl="~/images/btnAceptar.png" AlternateText="Aceptar"/>
                                    <asp:ImageButton ID="CancelButton" runat="server" ImageUrl="~/images/btnCancelar.png"  AlternateText="Cancelar"/>
                        </asp:Panel>
                        
                        
                        <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"  
                                    TargetControlID="lnkAddParent" PopupControlID="pnlActividades"
                                     BackgroundCssClass="modalBackground" 
                                    DropShadow="true" 
                                    
                                   
                                    CancelControlID="CancelButton" 
                                    
                                   
                                >
                        </cc1:ModalPopupExtender>
                        
                      </ContentTemplate>
                      </asp:UpdatePanel>
              
            </ItemTemplate>
        </asp:Repeater>
              
    
    <asp:SqlDataSource ID="dsActividades" runat="server" 
        ConnectionString="<%$ ConnectionStrings:gesworkConnectionString %>" 
        
            SelectCommand="SELECT TOP 1 Activity.ID, Activity.IDOwner,Activity.IDToUser,Oportunity.id as idoportunity,
                        Enterprise.ID as identerpise,Contact.id as idcontact,  Activity.OwneRByType, Contact.name,
                        Contact.firstname,Contact.lastname, Oportunity.Name AS oportunityName, Enterprise.Name As enterpriseName, Activity.Subject, 
                        Activity.MSG_Text, Activity.StartDate, Activity.DueDate, Activity.ACC_Type, ActivityType.Description AS tipo,
                         Activity.ACC_State, ActivityState.Description AS estado, Activity.ACC_IDPriority, ActivityPriority.Description AS prioridad ,
                        Activity.ACC_Categories, Activity.ACC_IDCampaign, Activity.ACC_IDParentActivity, Activity.FaxOrPhone, 
                        Activity.AllDayEvent, Activity.Layout, Activity.RecurrencePattern 

                        FROM Activity, Contact, Enterprise, Oportunity , ActivityType, ActivityPriority, ActivityState 

                        WHERE ((Enterprise.id= IDToUser AND  Activity.OwneRByType =1 ) or 
		                        (Contact.ID = IDToUser  AND  Activity.OwneRByType =2 ) OR 
		                        (Oportunity.id= IDToUser  AND  Activity.OwneRByType =0 )) 

                        AND (ActivityType.id=Activity.ACC_Type AND ActivityPriority.id=Activity.ACC_IDPriority 
                        AND ActivityState.id=Activity.ACC_State  AND Activity.ID=@ID)

					" 
             UpdateCommand="UPDATE [Activity] 
                SET [IDOwner] = @Owner, [OwnerByType] = @OwnerByType, [IDToUser] = @IDToUser, [Subject] = @Subject, 
                [MSG_Text] = @MSG_Text, [StartDate] = @StartDate, [DueDate] = @DueDate, [ACC_Type] = @ACC_Type, 
                [ACC_State] = @ACC_State, [ACC_IDPriority] = @ACC_IDPriority, [ACC_Categories] = @ACC_Categories, 
                [ACC_IDCampaign] = @ACC_IDCampaign, [ACC_IDParentActivity] = @ACC_IDParentActivity, [FaxOrPhone] = @FaxOrPhone, 
                [AllDayEvent] = @AllDayEvent, [Layout] = @Layout, [RecurrencePattern] = @RecurrencePattern 

                WHERE [ID] = @original_ID   " 

               >         
         <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="id" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Owner" Type="String" />
            <asp:Parameter Name="OwnerByType" Type="Int32" />
            <asp:Parameter Name="IDToUser" Type="String" />
            <asp:Parameter Name="Subject" Type="String" />
            <asp:Parameter Name="MSG_Text" Type="String" />
            <asp:Parameter Name="StartDate" Type="String"/>
            <asp:Parameter Name="DueDate" Type="String" />
            <asp:Parameter Name="ACC_Type" Type="Int32" />
            <asp:Parameter Name="ACC_State" Type="Int32" />
            <asp:Parameter Name="ACC_IDPriority" Type="Int32" />
            <asp:Parameter Name="ACC_Categories" Type="String" />
            <asp:Parameter Name="ACC_IDCampaign" Type="String" />
            <asp:Parameter Name="ACC_IDParentActivity" Type="String" />
            <asp:Parameter Name="FaxOrPhone" Type="String" />
            <asp:Parameter Name="AllDayEvent" Type="Boolean" />
            <asp:Parameter Name="Layout" Type="String" />
            <asp:Parameter Name="RecurrencePattern" Type="String" />
            <asp:Parameter Name="original_ID" Type="Int32" />
            <asp:Parameter Name="original_Owner" Type="Int32" />
            <asp:Parameter Name="original_OwnerByType" Type="Int32" />
            <asp:Parameter Name="original_IDToUser" Type="String" />
            <asp:Parameter Name="original_Subject" Type="String" />
            <asp:Parameter Name="original_MSG_Text" Type="String" />
            <asp:Parameter Name="original_StartDate" Type="String"/>
            <asp:Parameter Name="original_DueDate" Type="String"/>
            <asp:Parameter Name="original_ACC_Type" Type="Int32" />
            <asp:Parameter Name="original_ACC_State" Type="Int32" />
            <asp:Parameter Name="original_ACC_IDPriority" Type="Int32" />
            <asp:Parameter Name="original_ACC_Categories" Type="String" />
            <asp:Parameter Name="original_ACC_IDCampaign" Type="String" />
            <asp:Parameter Name="original_ACC_IDParentActivity" Type="String" />
            <asp:Parameter Name="original_FaxOrPhone" Type="String" />
            <asp:Parameter Name="original_AllDayEvent" Type="Boolean" />
            <asp:Parameter Name="original_Layout" Type="String" />
            <asp:Parameter Name="original_RecurrencePattern" Type="String" />
        </UpdateParameters>
        
    </asp:SqlDataSource>
    
    
       
    <br /><br />
                         <div class="separador"></div>   
                        <br />
    
    
                
<asp:ImageButton ID="UpdateButton" runat="server"  ImageUrl="~/images/btnGuardar.png"  CssClass="botones" onclick="btnEditar_Click" Text="Guardar" />
                
<asp:ImageButton ID="UpdateCancelButton" runat="server"  ImageUrl="~/images/btnCancelar.png"  CssClass="botones" Text="Cancelar"  PostBackUrl="~/actividades/activas.aspx" />
     </div>
    
       
    
    
    
    <br />
</p>
<p>
</p>
    </asp:content>

